package cn.sdormitory.controller;

import cn.sdormitory.common.api.CommonResult;
import cn.sdormitory.knowledgebase.dto.HandPaperDto;
import cn.sdormitory.knowledgebase.pojo.StudySkills;
import cn.sdormitory.knowledgebase.pojo.StudySkillsBatchExam;
import cn.sdormitory.knowledgebase.vo.AppUserAnswerRecordVo;
import cn.sdormitory.knowledgebase.vo.AppSkillsBatchUserVo;
import cn.sdormitory.knowledgebase.vo.StudyQuestionsVo;
import cn.sdormitory.service.AppStudySkillsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "app => 技能学习")
@RestController
@RequestMapping("/app/studySkills")
public class AppStudySkillsController {

    @Resource
    private AppStudySkillsService appStudySkillsService;

    @ApiOperation("app技能页面-根据用户id查询用户分配的技能任务")
    @GetMapping("/getSkillsBatchByUserId/{id}")
    public CommonResult<List<AppSkillsBatchUserVo>> getSkillsBatchByUserId(@PathVariable("id") Integer userId) {
        List<AppSkillsBatchUserVo> list = appStudySkillsService.getSkillsBatchByUserId(userId);
        return CommonResult.success(list);
    }

    @ApiOperation("app技能学习页面-根据技能id查询技能信息")
    @GetMapping("/getStudySkillsById/{id}")
    public CommonResult<StudySkills> getStudySkillsById(@PathVariable("id") Integer id) {
        StudySkills skills = appStudySkillsService.getStudySkillsById(id);
        return CommonResult.success(skills);
    }
    @ApiOperation("app技能学习页面-完成学习")
    @GetMapping("/completeLearning")
    public CommonResult completeLearning(@RequestParam("userId") Integer userId,
                                         @RequestParam("batchId") Integer batchId) {
        appStudySkillsService.completeLearning(userId,batchId);
        return CommonResult.success();
    }

    @ApiOperation("app答题页面-根据技能id获取需要考试的题目")
    @GetMapping("/getExamQuestionsById/{id}")
    public CommonResult<List<StudyQuestionsVo>> getExamQuestionsById(@PathVariable("id") Integer id) {
        List<StudyQuestionsVo> list = appStudySkillsService.getExamQuestionsById(id);
        return CommonResult.success(list);
    }
    @ApiOperation("app答题页面-根据考试记录id获取本次答题情况")
    @GetMapping("/getExamQuestionsResultByExamId/{id}")
    public CommonResult<List<StudyQuestionsVo>> getExamQuestionsResultByExamId(@PathVariable("id") Integer examId) {
        List<StudyQuestionsVo> studyQuestionsList = appStudySkillsService.getExamQuestionsResultByExamId(examId);
        return CommonResult.success(studyQuestionsList);
    }
    @ApiOperation("app答题页面-考试交卷")
    @PostMapping("/handPaper")
    public CommonResult<Integer> handPaper(@RequestBody HandPaperDto handPaperDto) {
        Integer examId = appStudySkillsService.handPaper(handPaperDto);
        return CommonResult.success(examId, "交卷成功");
    }

    @ApiOperation("app答题结果页面-根据考试id获取本次考试信息")
    @GetMapping("/getExamById/{id}")
    public CommonResult<StudySkillsBatchExam> getExamById(@PathVariable("id") Integer examId) {
        StudySkillsBatchExam batchExam = appStudySkillsService.getExamById(examId);
        return CommonResult.success(batchExam);
    }

    @ApiOperation("app我的答题页面-查询用户答题记录")
    @GetMapping("/getUserAnswerRecordList/{id}")
    public CommonResult<List<AppUserAnswerRecordVo>> getUserAnswerRecordList(@PathVariable("id") Integer userId) {
        List<AppUserAnswerRecordVo> list = appStudySkillsService.getUserAnswerRecordList(userId);
        return CommonResult.success(list);
    }









}
